<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8"/>
    <meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate"/>
    <meta http-equiv="Pragma" content="no-cache"/>
    <meta http-equiv="Expires" content="0"/>
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=2.0, user-scalable=no"/>
    <title>点赞留言管理</title>

    <script src="/Public/js/jquery-1.7.1.min.js"></script>
    <link href="/Public/css/bootstrap/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<div style="margin:0;
	padding:0;
	border:none;
	width:100%;
	height:100%;
	background:#000;
	z-index:10005;
	position:fixed;
	top:0;
	left:0;" id="body">
    <div style="width: 250px;margin: auto;margin-top: 40%;">
        <input class="form-control" type="text" id="cid">
        <button class="btn btn-success" style="margin-left: 40%;margin-top: 10%" onclick="check();">登录</button>
    </div>
</div>
<img src="" id="big" onclick="hide_big();" alt="" style="position: fixed;left: 0;top: 0;width: 100%;height: 100%;z-index: 100;display: none">
<div style="width: 100%;height: 100%;margin: 0;padding: 0;">
    <input type="hidden" id="praise" value="<?php echo I('get.praise', -1, '');?>">
    <div style="width: 100%;height: 84%;margin: 0;padding: 0;overflow: auto;position: fixed;word-break: break-all"
         id="content">
        <?php
            foreach($items as $item){
              echo "<div style='width:100%;height:12%;border:1px solid black;'>";
        echo "<div style='width: 80%;height:100%;float: left;overflow:hidden;word-break: break-all;'>";
        echo $item['content'] . "</div>";
        if($item['status'] == 0){
        echo "<button style='height:100%;float: left;width: 10%' onclick='comment_pass(" . $item['id'] . "," . $item['chat_id'] . ",this)'>通过</button>";
        }
        echo "<button style='height:100%;float: left;width: 10%' onclick='comment_delete(" . $item['id'] . "," . "this)'>删除</button>";
        echo "</div>";
    }
    ?>
</div>
<button style="width:100%;position: fixed;bottom: 0%;left:0;height: 8%;" onclick="more();">加载更多</button>
<!--<button style="width:50%;position: fixed;bottom: 0;left:0;height: 8%;background-color: #00a0e9" id="comment"
        onclick="change_type(0);">评论
</button>
<button style="width:50%;position: fixed;bottom: 0;left:50%;height: 8%;" id="item" onclick="change_type(1);">作品</button>-->
</div>
</body>
<script>
    var type = 0;
    function change_type(manage_type) {
        type = manage_type;
        $("#content").html('');
        page = 0;
        no_more = 0;
        if (manage_type == 0) {
            $("#comment").css("background-color", "#00a0e9");
            $("#item").css("background-color", "");
            more();
        } else {
            $("#item").css("background-color", "#00a0e9");
            $("#comment").css("background-color", "");
            item_more();
        }
    }
    var page = 1;
    function check(id, praise) {
        if ($("#cid").val() == "85312349") {
            $("#body").css("display", "none");
        }
    }

    function item_pass(id, obj) {
        if (confirm("确定通过？")) {
            $.ajax({
                type: 'get',
                dataType: 'json',
                url: '/Wap/Praiseeat/item_pass',
                data: {
                    itemId: id,
                    praise: $("#praise").val()
                },
                success: function (res) {
                    $(obj).remove();
                }
            });
        }
    }

    function item_delete(id, obj) {
        if (confirm("确定删除？")) {
            $.ajax({
                type: 'get',
                dataType: 'json',
                url: '/Wap/Praiseeat/item_delete',
                data: {
                    itemId: id,
                    praise: $("#praise").val()
                },
                success: function (res) {
                    $(obj).parent().remove();
                }
            });
        }
    }

    function comment_pass(id, itemid, obj) {
        if (confirm("确定通过？")) {
            $.ajax({
                type: 'get',
                dataType: 'json',
                url: '/Wap/Praiseeat/comment_pass',
                data: {
                    id: id,
                    item: itemid,
                    praise: $("#praise").val()
                },
                success: function (res) {
                    $(obj).remove();
                }
            });
        }
    }

    function comment_delete(id, obj) {
        if (confirm("确定删除？")) {
            $.ajax({
                type: 'get',
                dataType: 'json',
                url: '/Wap/Praiseeat/comment_delete',
                data: {
                    id: id,
                    praise: $("#praise").val()
                },
                success: function (res) {
                    $(obj).parent().remove();
                }
            });
        }
    }
    var no_more = 0;
    function more(){
        if(type == 0){
            comment_more();
        }else{
            item_more();
        }
    }
    function comment_more() {
        if (no_more == 0) {
            $.ajax({
                type: 'get',
                dataType: 'json',
                url: '/Wap/Praiseeat/comment_more',
                async: false,
                data: {
                    page: page,
                    praise: $("#praise").val()
                },
                success: function (res) {
                    var items = res['items'];
                    var content = '';
                    if (items.length > 0) {
                        for (var i = 0; i < items.length; i++) {
                            content += "<div style='width:100%;height:12%;border:1px solid black;'><div style='width: 80%;height:100%;float: left;overflow:hidden;word-break: break-all;'>";
                            content += items[i]['content'] + "</div>";
                            if (items[i]['status'] == 0) {
                                content += "<button style='height:100%;float: left;width: 10%' onclick='comment_pass(" + items[i]['id'] + "," + items[i]['chat_id'] + ",this)'>通过</button>";
                            }
                            content += "<button style='height:100%;float: left;width: 10%' onclick='comment_delete(" + items[i]['id'] + ",this)'>删除</button>";
                            content += "</div>";
                        }
                        $("#content").append(content);
                    } else {
                        alert("无更多内容");
                        no_more = 1;
                    }
                }
            });
            page = page + 1;
        }

    }
    function item_more() {
        if (no_more == 0) {

            $.ajax({
                type: 'get',
                dataType: 'json',
                url: '/Wap/Praiseeat/item_more',
                async: false,
                data: {
                    page: page,
                    praise: $("#praise").val()
                },
                success: function (res) {
                    var items = res['items'];
                    var content = '';
                    if (items.length > 0) {
                        for (var i = 0; i < items.length; i++) {
                            content += "<div style='width:100%;height:12%;border:1px solid black;'><img  onclick='show_big(this)' style='width: 30%;height:100%;float: left;overflow:hidden;' alt='' src='" + items[i]['pic'] + "'>";
                            content += "<div style='width: 45%;height:100%;float: left;overflow:hidden;word-break: break-all'>" + items[i]['show_name'] + "</div>";
                            if (items[i]['status'] == 9) {
                                content += "<button style='height:100%;float: left;width: 10%' onclick='item_pass(" + items[i]['id'] + ",this)'>通过</button>";
                            }
                            content += "<button style='height:100%;float: left;width: 10%' onclick='item_delete(" + items[i]['id'] + ",this)'>删除</button>";
                            content += "</div>";
                        }
                        $("#content").append(content);
                    } else {
                        alert("无更多内容");
                        no_more = 1;
                    }
                }
            });
            page = page + 1;
        }

    }
    var show = 0;
    function show_big(e) {
        show = 1;
        var imgobj = $(e);
        var img_src = imgobj.attr("src");
        $("#big").attr("src", img_src);
        $("#big").css("display", "block");
    }
    function hide_big(){
        $("#big").css("display", "none");
        $("#big").attr("src", "");
    }

</script>
</html>